//
//  CZCover.m
//  OCKSFWeibo
//
//  Created by 盛 发 况 on 16/4/18.
//  Copyright © 2016年 盛 发 况. All rights reserved.
//

#import "CZCover.h"

@implementation CZCover
// 设置浅灰色蒙板
- (void)setDimBackground:(BOOL)dimBackground {
    _dimBackground = dimBackground;
    
    if (dimBackground) {
        self.backgroundColor = [UIColor blackColor];
        self.alpha = 0.5;
    } else {
        self.alpha = 1;
        self.backgroundColor = [UIColor clearColor];
    }
}

/**
 *  显示蒙板
 */
+ (instancetype)show {

    CZCover *cover = [[CZCover alloc] initWithFrame:[UIScreen mainScreen].bounds];
    cover.backgroundColor = [UIColor clearColor];
    
    [CZKeyWindow addSubview:cover];

    return cover;
}

// 点击蒙板的时候做事情
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {

    // 移除蒙板
    [self removeFromSuperview];
    
    // 通知代理移除菜单
    if ([self.delegate respondsToSelector:@selector(coverDidClickCover:)]) {
        [self.delegate coverDidClickCover:self];
    }

}

@end



